package com.gm.controller.bill;

import com.github.miemiedev.mybatis.paginator.domain.PageList;
import com.github.miemiedev.mybatis.paginator.domain.Paginator;
import com.gm.common.Pager;
import com.gm.controller.dto.BillDTO;
import com.gm.model.Base.Const;
import com.gm.model.vo.ResMsg;
import com.gm.service.user.BillService;
import com.gm.tools.Common;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import java.util.List;
/**
 * 测试
 * Created by taojie on 17-6-21.
 */
@Controller
@RequestMapping("bill")
public class BillController {

    @Autowired
    private BillService billService;

    @RequestMapping("billList.web")
    public ModelAndView cardList(Pager pager, Integer cid){
        ModelAndView view= new ModelAndView();
        List<BillDTO> billList = billService.getAllList();
        for(int i=0; i < billList.size(); i++){
            billList.get(i).setCardNum(Common.getBankAccount(billList.get(i).getCardNum()));
        }
//        Paginator paginator = billList.getPaginator();
        view.addObject("billList", billList);
//        view.addObject("paginator", paginator);
        view.setViewName("/bill/bill.jsp");
        return view;
    }

    @RequestMapping(value = "dealed.do", method = RequestMethod.GET)
    @ResponseBody
    public ResMsg dealed(Integer blid,RedirectAttributes attr){
        ResMsg resMsg = new ResMsg();
        int ret =  billService.dealBill(blid);
        resMsg.setStatus(Const.RES_OK);
        return resMsg;
    }

    @RequestMapping(value = "cancelDeal.do", method = RequestMethod.GET)
    @ResponseBody
    public ResMsg cancelDeal(Integer blid, RedirectAttributes attr){
        ResMsg resMsg = new ResMsg();
        int ret =  billService.cancelDealBill(blid);
        resMsg.setStatus(Const.RES_OK);
        return resMsg;
    }

}
